"""
@Author：WangYuXiang
@E-mile：Hill@3io.cc
@CreateTime：2021/4/22 17:03
@DependencyLibrary：无
@MainFunction：无
@FileDoc： 
    qr.py
    文件说明
@ChangeHistory:
    datetime action why
    example:
    2021/4/22 17:03 change 'Fix bug'
        
"""

from apps.school.models import SchoolModel, ClassModel, StudentModel
from sanic_rest_framework.fields import CharField, IntegerField
from sanic_rest_framework.serializers import ModelSerializer, Serializer


class SchoolSerializer(ModelSerializer):
    president = CharField(source='president.nickname')

    class Meta:
        model = SchoolModel
        read_only_fields = ('id',)


class ClassSerializer(ModelSerializer):
    class_man = CharField(source='class_man.nickname')
    school = CharField(source='school.name')

    class Meta:
        model = ClassModel
        read_only_fields = ('id',)


class StudentSerializer(ModelSerializer):
    in_class = CharField(source='in_class.name')

    class Meta:
        model = StudentModel
        read_only_fields = ('id',)


class SearchSerializer(Serializer):
    """用户搜索"""
    value = CharField(source='name', read_only=True)
    key = IntegerField(source='id', read_only=True)
